local tuxi = fk.CreateSkill {

  name = "joyex__tuxi",

  tags = {  },

}



tuxi:addEffect(fk.DrawNCards, {
  name = "joyex__tuxi",
  anim_type = "control",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(tuxi.name) and data.n > 0 and
      not table.every(player.room:getOtherPlayers(player), function(p) return p:isKongcheng() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
      return not p:isKongcheng() end), function (p) return p.id end)
    local tos = room:askForChoosePlayers(player, targets, 1, data.n, "#joyex__tuxi-choose:::"..data.n, tuxi.name, true)
    if #tos > 0 then
      event:setCostData(self, tos)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(event:getCostData(self)) do
      local c = room:askForCardChosen(player, room:getPlayerById(id), "h", tuxi.name)
      room:obtainCard(player, c, false, fk.ReasonPrey)
      local card = Fk:getCardById(c)
      room:setCardMark(card,"@@joyex__zhengbing-inhand",1)
    end
    data.n = data.n - #event:getCostData(self)
  end,
})

return tuxi